﻿package mvc_model
{
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	
	public class RegisterCommand
	{
		// url of register.php script
		private var REGISTER_PHP = "http://localhost/php/register.php";
		
		// user data
		private var _username:String;
		private var _password:String;
		private var _firstName:String;
		private var _lastName:String;
		private var _email:String;
		private var _dob:String;
		private var _city:String;
		private var _country:String;
		private var _gender:String;
		private var _availability:String;
		private var _picture:String;
		
		public function RegisterCommand(username:String,
										password:String,
										firstName:String,
										lastName:String,
										email:String,
										dob:String,
										city:String,
										country:String,
										gender:String,
										availability:String,
										picture:String)
		{
			_username     = username;
			_password	  = password;
			_firstName    = firstName;
			_lastName     = lastName;
			_email        = email;
			_dob          = dob;
			_city         = city;
			_country      = country;
			_gender       = gender;
			_availability = availability;
			_picture      = picture;
		}
		
		// execute the register user command 
		public function execute():void
		{
			var request:URLRequest = new URLRequest(REGISTER_PHP);
			
			// init variables to pass to register.php
			var variables:URLVariables = new URLVariables();
			variables.username     = _username;
			variables.firstName    = _firstName;;
			variables.password     = _password;
			variables.lastName     = _lastName;
			variables.email        = _email;
			variables.dob          = _dob;
			variables.city         = _city;
			variables.country      = _country;
			variables.gender       = _gender;
			variables.availability = _availability;
			variables.picture      = _picture;

			request.data = variables;
			request.method = "GET";
			
			// execute script
			var loader:URLLoader = new URLLoader(request);
		}
	}
}